
#ifndef __SPI_MTD_H__
#define	__SPI_MTD_H__
#include "sys.h"
#include "xrj_common_datatype.h"

/*硬件定义*/


// 常量定义
//#define	Block_Max		50
#define	Block_Size		W25QXX_SECPOS
#define	Block_DATA		4000
#define	Block_Reserve	96



#define CARD_FIND		0 
#define CARD_ROM_FULL  	1
#define CARD_NO_FIND	2 





#define	MTD_Block_Num_Factory		1
#define	MTD_Block_Num_IDCard		63
#define	MTD_Block_Num_Password		64
#define	MTD_Block_Num_PrgInit		64
#define	MTD_Block_Num_PrgUpdate		64


#define	MTD_Block_Start_Factory		0
#define	MTD_Block_Start_IDCard		(MTD_Block_Start_Factory+MTD_Block_Num_Factory)
#define	MTD_Block_Start_Password	(MTD_Block_Start_IDCard+MTD_Block_Num_IDCard)
#define	MTD_Block_Start_PrgInit		(MTD_Block_Start_Password+MTD_Block_Num_Password)
#define	MTD_Block_Start_PrgUpdate	(MTD_Block_Start_PrgInit+MTD_Block_Num_PrgInit)

#define	MTD_Block_MAX				512



//	MTD_Block_Start_Factory

#define	Set_UnlockWarnEn_Len		1
#define	Set_LockTime_Len			1
#define	Set_SwitchMode_Len			1
#define	Set_TamperAlarmEn_Len		1


#define	Set_UnlockWarnEn_Offset		10
#define	Set_LockTime_Offset			(Set_UnlockWarnEn_Offset+Set_UnlockWarnEn_Len)
#define	Set_SwitchMode_Offset		(Set_LockTime_Offset+Set_LockTime_Len)				
#define	Set_TamperAlarmEn_Offset	(Set_SwitchMode_Offset+Set_SwitchMode_Len)

#define	UUID_Offset					1024
#define	UUID_Len					16
#define	PRODUCTKEY_Offset			(UUID_Offset+UUID_Len)
#define	PRODUCTKEY_Len				16



/*外部变量声明*/




/*外部函数声明*/
uint8_t	 MTD_SPI_Search(UINT32 AddrMtd_Start, uint8_t *buf, uint16_t size, uint32_t *rom_addr);
uint8_t MTD_SPI_Delete(UINT32 AddrMtd_Start, uint8_t *buf, uint16_t size);
uint8_t MTD_SPI_ADD(UINT32 AddrMtd_Start,uint8_t *buf, uint16_t size);
uint16_t MTD_SPI_GET_Num(UINT32 AddrMtd_Start,uint16_t size);
uint16_t MTD_SPI_Del_Groud(UINT32 AddrMtd_Start);
uint16_t MTD_SPI_Erase_Block(UINT32 AddrMtd_Start);

UINT8 MTD_SPI_GET_Check(UINT32 AddrMtd_Start, UINT32 Offset, UINT16 size);

INT32 MTD_SPI_Set_Write(UINT32 AddrMtd_Start, UINT32 Offset, UINT8 *buf, UINT16 size);
INT32 MTD_SPI_Set_Read(UINT32 AddrMtd_Start, UINT32 Offset, UINT8 *buf, UINT16 size);


uint8_t	 MTD_SPI_Search_Lock(UINT32 AddrMtd_Start, uint8_t *buf, uint16_t size, uint32_t *rom_addr);
uint8_t MTD_SPI_Delete_Lock(UINT32 AddrMtd_Start, uint8_t *buf, uint16_t size);
uint8_t MTD_SPI_ADD_Lock(UINT32 AddrMtd_Start,uint8_t *buf, uint16_t size);
uint16_t MTD_SPI_GET_Num_Lock(UINT32 AddrMtd_Start,uint16_t size);
uint16_t MTD_SPI_Del_Groud_Lock(UINT32 AddrMtd_Start);
uint16_t MTD_SPI_Erase_Block_Lock(UINT32 AddrMtd_Start);

UINT8 MTD_SPI_GET_Check_Lock(UINT32 AddrMtd_Start, UINT32 Offset, UINT16 size);

INT32 MTD_SPI_Set_Write_Lock(UINT32 AddrMtd_Start, UINT32 Offset, UINT8 *buf, UINT16 size);
INT32 MTD_SPI_Set_Read_Lock(UINT32 AddrMtd_Start, UINT32 Offset, UINT8 *buf, UINT16 size);


INT32 MTD_SPI_Set_Init(void);
INT32 MTD_SPI_UUID_KEY(void);
#endif

